<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { timeFormat, toYuan, copyToCliboard, timeFormat_2 } from '@/hooks/util'
import * as preQuotationApi from '@/api/preQuotation'
import * as accountApi from '@/api/account'
import * as quotationRulesApi from '@/api/quotationRules'
import AddRule from './components/AddRule.vue'
import Modal from '../../components/Modal/index.vue'
import addTemplateContent from './components/AddTemplate.vue'
import { message } from 'ant-design-vue'
import SendTemplate from './components/SendTemplateWX.vue'
import * as CinemasApi from '@/api/Cinemas'
import * as tempalteApi from '@/api/template'
const screenWidth = ref(0)
const screenHeight = ref(0)

const AddTemplateRef = ref()
const sendTemplateRef = ref()

function updateScreenSize() {
  screenWidth.value = window.innerWidth
  screenHeight.value = window.innerHeight
  console.log(screenWidth.value, screenHeight.value, 'screenWidth.value, screenHeight.value')
}
const route = useRoute()
const router = useRouter()

const addRuleRef = ref()

interface Pagination {
  page: number
  pageSize: number
  total: number
  current?: number
  onChange: Function
  showSizeChanger: boolean
}

const handlePageChange = (page: any, pageSize: any) => {
  pagination.value.pageSize = pageSize
  searchParams.value.pageSize = pageSize
}

const pagination = ref<Pagination>({
  page: 1,
  pageSize: 10,
  total: 0,
  onChange: handlePageChange,
  showSizeChanger: true,
})
let loading = ref<boolean>(false)

interface SearchParams {
  currentPage: number
  pageSize: number
  channel: number
  [propName: string]: any
}
const searchParams = ref<SearchParams>({
  channel: 1, // 微信
  currentPage: pagination.value.page,
  pageSize: pagination.value.pageSize,
})
interface Pagination1 {
  page: number
  pageSize: number
  total: number
  current?: number
  onChange: Function
  showSizeChanger: boolean
}

const handlePageChange1 = (page: any, pageSize: any) => {
  pagination1.value.pageSize = pageSize
}

const pagination1 = ref<Pagination1>({
  page: 1,
  pageSize: 10,
  total: 0,
  onChange: handlePageChange1,
  showSizeChanger: true,
})
let loading1 = ref<boolean>(false)

interface SearchParams1 {
  currentPage: number
  pageSize: number
}
const searchParams1 = ref<SearchParams1>({
  currentPage: pagination1.value.page,
  pageSize: pagination1.value.pageSize,
})

const dataSource = ref([])
const dataSource1 = ref([])

const columns1 = [
  // {
  //   title: 'ID',
  //   key: 'id',
  //   width: 200,
  // },
  {
    title: '院线名称',
    key: 'lineName',
    width: 200,
  },

  {
    title: '影院数量',
    key: 'cinemaCount',
    width: 200,
  },
  {
    title: '操作',
    key: 'action',
    width: 150,
    fixed: 'right',
    align: 'center',
  },
]

const columns = [
  {
    title: '名称/院线',
    key: 'name',
    width: 400,
  },
  {
    title: '排除影院/规则权重',
    key: 'cinemaList',
    width: 400,
  },
  {
    title: '报价出票模式',
    key: 'ticketMode',
    width: 400,
  },
  // {
  //   title: '首选渠道/备选渠道',
  //   key: 'matchChannel',
  //   width: 180,
  // },
  {
    title: '报价调整类型/报价方式',
    key: 'finalPriceAdjustType',
    width: 400,
  },
  // {
  //   title: '报价方式',
  //   key: 'quotationType',
  //   width: 120,
  // },
  {
    title: '报价金额/是否限价',
    key: 'quotationAmount',
    width: 400,
  },
  // {
  //   title: '是否限价',
  //   key: 'enableLimitPrice',
  //   width: 120,
  // },
  {
    title: '启用状态',
    key: 'status',
    width: 400,
  },
  {
    title: '生效时间段',
    key: 'timePeriod',
    width: 400,
  },
  {
    title: '操作',
    key: 'action',
    width: 200,
    fixed: 'right',
    align: 'center',
  },
]

// 翻页
const changePage = (e: any) => {
  pagination.value.current = e.current
  pagination.value.pageSize = e.pageSize
  searchParams.value.currentPage = pagination.value.current as number
  getList()
}
const changePage1 = (e: any) => {
  pagination1.value.current = e.current
  pagination1.value.pageSize = e.pageSize
  searchParams1.value.currentPage = pagination1.value.current as number
  // getList()
  getCinemaList()
}

const getList = async () => {
  loading.value = true
  try {
    let {
      state,
      data,
      message: msg,
    } = await preQuotationApi.getSimpleQuotationList(searchParams.value)
    if (state === 200) {
      dataSource.value = data.list.map((item: any) => {
        item.statusFlag = item.status === 1
        return item
      })
      pagination.value.total = Number(data.totalCount)
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
  loading.value = false
}

import type { SelectProps } from 'ant-design-vue'
const orderStatusList = ref<SelectProps['options']>([
  {
    label: '禁用',
    value: 0,
  },
  {
    label: '启用',
    value: 1,
  },
])

const ticketChannelList = ref<SelectProps['options']>([
  {
    label: '麻花电影票',
    value: 3,
  },
  {
    label: '守兔电影票',
    value: 11,
  },
  {
    label: '守兔',
    value: 7,
  },
  {
    label: '芒果电影票',
    value: 5,
  },
  {
    label: '哈哈电影快票',
    value: 9,
  },
  {
    label: '星驰电影票',
    value: 8,
  },
  {
    label: '影划算电影票',
    value: 10,
  },
])

const formRef = ref()
interface FormState {
  name?: string
  status?: number
  ticketChannel?: number
  [propName: string]: any
}
const formState = reactive<FormState>({})

// 查询
const search = () => {
  pagination.value.current = 1
  searchParams.value.currentPage = 1
  formRef.value.validate().then(() => {
    searchParams.value.name = formState.name || ''

    if (formState.name != '') {
      searchParams.value.name = formState.name
    }

    if (formState.ticketChannel) {
      searchParams.value.ticketChannel = formState.ticketChannel
    }

    if (formState.status == 0 || formState.status == 1) {
      searchParams.value.status = formState.status
    }
    getList()
  })
}

// 重置
const reset = () => {
  pagination.value.current = 1
  searchParams.value.currentPage = 1
  formRef.value.resetFields()
  for (let key in searchParams.value) {
    if (key != 'currentPage' && key != 'pageSize' && key != 'channel' && key != 'robotId')
      searchParams.value.hasOwnProperty(key) && delete searchParams.value[key]
  }
  getList()
}

// 新增规则
const add = () => {
  addRuleRef.value.showModal(1, okRobat.value)
}

// 编辑规则
const edit = (record: Object) => {
  addRuleRef.value.showModal(1, okRobat.value, record)
}

const activeKey = ref<string>('1')

onMounted(() => {
  getRobatList()
  getGroupList()
  updateScreenSize()
})

// 拉取机器人列表
let okRobat = ref<string>()
const robatList = ref<SelectProps['options']>([])

interface OptionList {
  label: string
  value: string
}
let optionList = ref<Array<OptionList>>([])
const getRobatList = async () => {
  const params = {
    currentPage: 1,
    pageSize: 100,
  }
  try {
    let { state, data, message: msg } = await accountApi.getList(params)
    if (state === 200) {
      robatList.value = data.list
      optionList.value = data.list.map((item: any) => {
        return {
          label: item.nickName,
          value: item.id,
        }
      })

      optionsArr.value = data.list
      if (data.list.length == 0) {
        if (dataSource.value.length == 0) {
          // activeKey.value = '2'
        }
      } else if (data.list.length > 0) {
        selectRobat(data.list[0].id)
      }
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
}
const selectRobat = (selectValue: unknown) => {
  okRobat.value = selectValue as string
  searchParams.value.robotId = okRobat.value
  getList()
}

// 推送
const groupList = ref<SelectProps['options']>([])
const groupId = ref<string>()
const optionsArr = ref<SelectProps['options']>([])
const getGroupList = async () => {
  try {
    let { state, data, message: msg } = await accountApi.getWechatRobotGroupList()
    if (state === 200) {
      groupList.value = data
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
}
const selectGroup = (selectValue: any) => {
  groupId.value = selectValue as string
  sendRobat.value = optionsArr
    .value!.filter(item => item.groupId == groupId.value)
    .map(item => item.id)
}

// 推送配置
let sendRobat = ref<Array<string>>()
const selectSendRobat = (selectValue: any) => {
  sendRobat.value = selectValue
}
const pushRobot = async () => {
  // console.log('okRobat=', okRobat.value)
  // console.log('sendRobat=', sendRobat.value)
  let params = {
    acceptRobotIds: sendRobat.value,
    channel: 1,
    sendRobotId: okRobat.value,
  }
  try {
    const { state, message: msg } = await preQuotationApi.simpleQuotationPushRobots(params)
    if (state === 200) {
      message.success('操作成功')
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
}
const sendOk = () => pushRobot()

// select搜索
const filterOption = (input: string, option: any) => {
  return option.label.indexOf(input) >= 0
}

// 删除
const del = async (id: string) => {
  try {
    const { state, message: msg } = await preQuotationApi.deleteSimpleQuotation({ id })
    if (state === 200) {
      message.success('删除成功')
      getList()
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
}

const handleChangeRules = async (record: any) => {
  try {
    const { state, message: msg } = await preQuotationApi.editSimpleQuotationStatus({
      id: record.id,
      status: record.status ? 0 : 1,
    })
    if (state === 200) {
      message.success('操作成功')
      getList()
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
}

// 简易预报价
const preQuotation = () => {
  router.push({ path: '/pre-quotation' })
}

// 获取 模板id
let TemplateId = ref('')
const getTHEID = id => {
  console.log('id=', id)
  TemplateId.value = id
}

// 弹框确定
const handleConfirm = async () => {
  // AddTemplateRef.value.setVisible(false)

  console.log('okRobat=====', okRobat.value)
  console.log('TemplateId=====', TemplateId.value)

  try {
    const { state, message: msg } = await tempalteApi.installGroupSimpleQuotation({
      groupId: TemplateId.value,
      robotId: okRobat.value,
    })
    if (state === 200) {
      message.success('操作成功')
      AddTemplateRef.value.setVisible(false)
    } else {
      message.error(msg)
    }
  } catch (error) {
    message.error('网络请求连接失败~')
  }
}
//自定义影院设置
let CustomizeRef = ref(null)

const cameraDataSet = () => {
  getCinemaList()
  CustomizeRef.value.setVisible(true)
}

//获取自定义院线列表
const getCinemaList = async () => {
  try {
    let { state, data, message: msg } = await CinemasApi.CinemaList(searchParams1.value)
    if (state == 200) {
      dataSource1.value = data.list
      pagination1.value.total = Number(data.totalCount)
    } else {
      message.error(msg)
    }
  } catch (error) {
    console.log(error, 'error')

    message.error('操作失败~')
  }
}

let CinemasRef = ref(null)

const CameraForm = ref({
  name: '',
})
const handleConfiormAddCamera = async () => {
  if (CameraForm.value.name == '') {
    message.error('请输入院线名称')
    return
  }
  try {
    let {
      state,
      data,
      message: msg,
    } = await CinemasApi.AddCinema({
      lineName: CameraForm.value.name,
    })
    if (state == 200) {
      message.success('添加成功')
      CinemasRef.value.setVisible(false)
      getCinemaList()
    } else {
      message.error(msg)
    }
  } catch (error) {
    console.log(error, 'error')

    message.error('操作失败~')
  }
}
let AssociatedRef = ref(null)
//关联影院
const handleConfiormAssociated = async () => {
  if (selectedCinemaList.value.length == 0) {
    message.error('请选择影院')
    return
  }
  selectedCinemaList.value = selectedCinemaList.value.map(item => {
    return {
      ...item,
      cinemaId: item.cinemaId,
    }
  })

  try {
    let {
      state,
      data,
      message: msg,
    } = await CinemasApi.RelCinema({
      lineId: associatedForm.value.id,
      relS: selectedCinemaList.value,
    })
    if (state == 200) {
      message.success('关联成功')
      AssociatedRef.value.setVisible(false)
      getCinemaList()
    } else {
      message.error(msg)
    }
  } catch (error) {
    console.log(error, 'error')

    message.error('操作失败~')
  }
}
let associatedForm = ref({})

let cinemasValue = ref('')
//搜索
const onCinemasSearch = () => {}
//关联影院
const Associated = async (record: any) => {
  associatedForm.value = record
  getCityList()
  // setTimeout(() => {
  AssociatedRef.value.setVisible(true)
  getAassociatedList()
  // }, 1000)
}
//删除
const handleDelete = async (record: any) => {
  try {
    let {
      state,
      data,
      message: msg,
    } = await CinemasApi.delCinema({
      id: record.id,
    })
    if (state == 200) {
      message.success('删除成功')
      getCinemaList()
    } else {
      message.error(msg)
    }
  } catch (error) {
    console.log(error, 'error')

    message.error('操作失败~')
  }
}

let cityVal = ref(0)

//监听店铺选择
watch(cityVal, newVal => {
  CinemaParams.value.currentPage = 1
  allCheck.value = false
  // searchValue.value = ''
  CinemaParams.value.pageSize = 100
  delete CinemaParams.value.cinemaName
  getCinema(cityVal.value, 0)
})
let cityList = ref([])
const getCityList = async () => {
  try {
    let { state, data, message: msg } = await CinemasApi.getCity()
    if (state == 200) {
      console.log(data, '1')

      cityList.value = data.map(item => {
        return {
          label: item.cityName,
          value: item.id,
        }
      })
      cityList.value.unshift({
        label: '全部',
        value: 0,
      })

      getCinema(cityVal.value, 0)
    } else {
      message.error(msg)
    }
  } catch (error) {}
}

const selectCity = (selectValue: unknown) => {
  cityVal.value = selectValue as string
  // searchParams.value.robotId = okRobat.value
  // getList()
}

const CinemaList = ref([]) //左边的数据
const allCheck = ref(false) //总选中框
const selectedCinemaList = ref([]) //右边的数据
const TemporaryList = ref([]) //暂存的数据
const CinemaParams = ref({ currentPage: 1, pageSize: 100, cinemaName: '' })

//全选操作
const handelAllChecked = e => {
  if (e.target.checked) {
    CinemaList.value.forEach(item => {
      item.state = true
      const isInSelectedList = TemporaryList.value.some(
        existingItem => existingItem.cinemaId === item.cinemaId,
      )
      if (!isInSelectedList) {
        TemporaryList.value.push(item)
      }
    })
  } else {
    CinemaList.value.forEach(item => {
      item.state = false
    })
    TemporaryList.value = []
  }
}

//滚动scroll
const scrollBox = ref()
const handleScroll = () => {
  if (scrollBox.value.scrollTop + scrollBox.value.clientHeight >= scrollBox.value.scrollHeight) {
    // 滚动到底部的逻辑
    CinemaParams.value.currentPage++
    getCinema(cityVal.value, 1)
    // 例如，你可以在这里发起一个请求来加载更多数据
  }
}

// 获取影院列表 0 筛选 1 分页
const getCinema = async (areaId: any, type: any) => {
  CinemaParams.value.areaId = areaId
  if (!CinemaParams.value.areaId) {
    delete CinemaParams.value.areaId
  }
  try {
    let { state, data, message: msg } = await CinemasApi.GetCinemaList(CinemaParams.value)
    if (state === 200) {
      data.list.forEach(item => {
        item.state = false
        item.cinemaId = item.id
      })

      if (type) {
        CinemaList.value = [...CinemaList.value, ...data.list]
        allCheck.value = CinemaList.value.every(item => item.state)
      } else {
        CinemaList.value = data.list
      }
    } else {
      message.error(msg)
    }
  } catch (error) {
    console.log(error, 'error')

    message.error('网络请求连接失败~')
  }
}
//全选判断
const isCheckedAll = () => {
  return CinemaList.value.every(item => item.state)
}
//右侧选择项 处理
const selectedGoodsItem = async (item: any, index: any) => {
  if (item.state) {
    TemporaryList.value.push(item)
  } else {
    // 如果复选框被取消选中，从 TemporaryList 中移除 item
    const indexToRemove = TemporaryList.value.findIndex(
      listItem => listItem.cinemaId === item.cinemaId,
    )
    if (indexToRemove !== -1) {
      TemporaryList.value.splice(indexToRemove, 1)
    }
  }
  allCheck.value = await isCheckedAll()
}
//删除宝贝项
const deleteGoodsItem = async (index: any, item: any) => {
  TemporaryList.value.splice(index, 1)
  selectedCinemaList.value.splice(index, 1)
  CinemaList.value.forEach(row => {
    if (row.cinemaId === item.cinemaId) {
      row.state = false
    }
  })
  allCheck.value = await isCheckedAll()
}

//选择宝贝到右侧
const handleClickTemporary = () => {
  // selectedCinemaList.value = []
  if (TemporaryList.value.length) {
    TemporaryList.value.forEach((item1: any) => {
      // selectedGoodsList.value.//右边数据
      const isInSelectedList = selectedCinemaList.value.some(
        (item2: any) => item1.cinemaId === item2.cinemaId,
      )
      if (!isInSelectedList) {
        selectedCinemaList.value.push(item1)
      }
    })
  }
  console.log(selectedCinemaList.value, CinemaList.value)

  selectedCinemaList.value.forEach(item1 => {
    CinemaList.value.forEach(item2 => {
      if (item1.cinemaId == item2.cinemaId) {
        item1 = item2
      }
    })
  })
}

const onSearchCinema = () => {
  CinemaParams.value.currentPage = 1
  allCheck.value = false

  getCinema(cityVal.value, 0)
}

const getAassociatedList = async () => {
  try {
    let {
      state,
      data,
      message: msg,
    } = await CinemasApi.GetHistoryList({
      lineId: associatedForm.value.id,
    })
    if (state == 200) {
      console.log(data, '1')
      data.forEach(item => {
        CinemaList.value.forEach(row => {
          if (row.id == item.cinemaId) {
            row.state = true
          }
        })
      })
      selectedCinemaList.value = data
    } else {
      message.error(msg)
    }
  } catch (error) {}
}
const  addTemplateContentRef=ref()
const SettingTemplate=()=>{
  AddTemplateRef.value.setVisible(true)
  addTemplateContentRef.value.dispthChild()

}
</script>

<template>
  <div style="margin: 5px 0; text-align: right">
    <span>选择闲鱼账号：</span>
    <a-select v-model:value="okRobat" @change="selectRobat" placeholder="请选择" style="width: 200px; text-align: left"
      show-search :options="optionList" :filter-option="filterOption">
      <a-select-option v-for="(item, index) in optionList" :key="index" :value="item.value">
        {{ item.label }}
      </a-select-option>
    </a-select>
  </div>

  <div class="searchBox">
    <a-form ref="formRef" layout="inline" :model="formState">
      <a-form-item label="名称" name="name">
        <a-input v-model:value="formState.name" placeholder="名称" style="width: 200px" />
      </a-form-item>

      <a-form-item label="状态" name="status">
        <a-select v-model:value="formState.status" placeholder="状态" style="width: 200px" allowClear>
          <a-select-option v-for="(item, index) in orderStatusList" :key="index" :value="item.value">
            {{ item.label }}
          </a-select-option>
        </a-select>
      </a-form-item>

      <!-- <a-form-item label="询价渠道" name="ticketChannel">
        <a-select
          v-model:value="formState.ticketChannel"
          placeholder="询价渠道"
          style="width: 200px"
          allowClear
        >
          <a-select-option
            v-for="(item, index) in ticketChannelList"
            :key="index"
            :value="item.value"
          >
            {{ item.label }}
          </a-select-option>
        </a-select>
      </a-form-item> -->

      <a-form-item>
        <a-button type="primary" @click="search">搜索</a-button>
        <a-button @click="reset">重置</a-button>
        <a-button type="primary" @click="add">新增规则</a-button>
        <a-button type="primary" @click="sendTemplateRef.showModal()">模板列表</a-button>
        <a-button type="primary" @click="cameraDataSet">自定义院线设置</a-button>

        <!-- <a-button type="primary" @click="preQuotation">（专业）自定义规则设置</a-button> -->
      </a-form-item>
    </a-form>
  </div>

  <a-alert description="小提示：只要鼠标在表格上，按住左Shift键并滚动鼠标滚轮就可以横向滚动表格" type="info" banner
    style="margin-bottom: 10px; padding: 10px" />

  <a-table style="overflow-x: scroll" :columns="columns" :data-source="dataSource" :pagination="pagination"
    :loading="loading" @change="changePage" rowKey="id" :scroll="{ x: 100 }">
    <template #emptyText>
      <a-empty description="暂无数据" />
    </template>

    <template #headerCell="{ column }"></template>

    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'name'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '100px' }">
          <a-descriptions-item label="规则名称">
            <a-tooltip placement="top">
              <template #title>
                <span>{{ record.name }}</span>
              </template>
              <span class="hiddenText">{{ record.name }}</span>
            </a-tooltip>
          </a-descriptions-item>
          <a-descriptions-item label="院线">
            <a-tooltip placement="top">
              <template #title>
                <a-tag color="blue" v-for="item in record.lineList" :key="item">
                  {{ item.lineName }}
                </a-tag>
              </template>
              <div class="hiddenText">
                <a-tag style="line-height: 16px" color="blue" v-for="item in record.lineList" :key="item">
                  {{ item.lineName }}
                </a-tag>
              </div>
            </a-tooltip>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-if="column.key === 'cinemaList'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '100px' }">
          <a-descriptions-item label="排除影院">
            <a-tooltip placement="top">
              <template #title>
                <a-tag color="blue" v-for="item in record.cinemaList" :key="item">
                  {{ item.name }}
                </a-tag>
              </template>
              <div class="hiddenText">
                <a-tag style="line-height: 16px" color="blue" v-for="item in record.cinemaList" :key="item">
                  {{ item.name }}
                </a-tag>
              </div>
            </a-tooltip>
          </a-descriptions-item>
          <a-descriptions-item label="规则权重">
            {{ record.sort || 0 }}
          </a-descriptions-item>
        </a-descriptions>
      </template>
      <template v-if="column.key === 'ticketMode'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '100px' }">
          <a-descriptions-item label="报价出票模式">
            <a-tag color="blue" v-if="record.quotationMode == 2">渠道一口价</a-tag>
            <a-tag color="blue" v-if="record.quotationMode == 1">渠道预估价</a-tag>
            <a-tag color="blue" v-if="record.quotationMode == 3">场景预估价</a-tag>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-else-if="column.key === 'ticketChannel'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '100px' }">
          <a-descriptions-item label="询价渠道">
            <a-tag color="blue" v-if="record.ticketChannel == 3">麻花电影票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 11">守兔电影票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 7">守兔</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 6">哈哈电影票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 5">芒果电影票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 9">哈哈电影快票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 8">星驰电影票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 10">影划算电影票</a-tag>
            <a-tag color="blue" v-if="record.ticketChannel == 99">动态渠道</a-tag>
          </a-descriptions-item>
          <a-descriptions-item label="供应渠道">
            <a-tag color="blue" v-if="record.matchChannel == 3">麻花电影票（可限价）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 11">守兔电影票（一口价）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 7">守兔电影票（可限价）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 5">芒果电影票（一口价）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 6">哈哈电影票</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 9">哈哈电影快票（固定9折）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 8">星驰电影票（一口价）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 10">影划算电影票（可限价）</a-tag>
            <a-tag color="blue" v-if="record.matchChannel == 99">动态渠道</a-tag>

            <a-tag color="blue" v-if="record.slaveMatchChannel == 3">麻花电影票（可限价）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 6">哈哈电影票</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 11">守兔电影票（一口价）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 7">守兔电影票（可限价）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 5">芒果电影票（一口价）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 9">哈哈电影快票（固定9折）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 8">星驰电影票（一口价）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 10">影划算电影票（可限价）</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 0">不使用</a-tag>
            <a-tag color="blue" v-if="record.slaveMatchChannel == 99">动态渠道</a-tag>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-else-if="column.key === 'finalPriceAdjustType'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '140px' }">
          <a-descriptions-item label="报价调整类型">
            <span v-if="record.finalPriceAdjustType == 1">四舍五入到整数元</span>
            <span v-if="record.finalPriceAdjustType == 2">四舍五入到元-0.1</span>
            <span v-if="record.finalPriceAdjustType == 3">到0.5/整数元</span>
            <span v-if="record.finalPriceAdjustType == 0">不调整</span>
          </a-descriptions-item>
          <a-descriptions-item label="报价方式">
            <span v-if="record.quotationType == 1">加法</span>
            <span v-if="record.quotationType == 2">减法</span>
            <span v-if="record.quotationType == 3">比例（百分比加法）</span>
            <span v-if="record.quotationType == 4">比例（百分比减法）</span>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-else-if="column.key === 'quotationAmount'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '120px' }">
          <a-descriptions-item label="报价金额">
            <span v-if="record.quotationType == 1">
              预估成本
              <span style="color: red">+</span>
              {{ Math.abs(toYuan(record.discount) as any) }} ￥
            </span>
            <span v-if="record.quotationType == 2">
              预估成本
              <span style="color: red">-</span>
              {{ Math.abs(toYuan(record.discount) as any) }} ￥
            </span>
            <span v-if="record.quotationType == 3">
              预估成本
              <span style="color: red">*</span>
              (1 + {{ record.percent }}%)
            </span>
            <span v-if="record.quotationType == 4">
              预估成本
              <span style="color: red">*</span>
              (1 {{ record.percent }}%)
            </span>
          </a-descriptions-item>
          <a-descriptions-item label="是否限价">
            <div v-if="record.quotationMode == 1 || record.quotationMode == 3">
              <a-tag color="blue" v-if="record.enableLimitPrice == 1">启用</a-tag>
              <a-tag color="red" v-if="record.enableLimitPrice == 0">不启用</a-tag>
            </div>
            <div v-else>无需设置</div>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-else-if="column.key === 'status'">
        <!-- <a-tag color="red" v-if="record.status == 0">禁用</a-tag>
        <a-tag color="blue" v-if="record.status == 1">启用</a-tag> -->

        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '120px' }">
          <a-descriptions-item label="启用状态">
            <a-switch v-model:checked="record.statusFlag" @change="handleChangeRules(record)" />
          </a-descriptions-item>
          <a-descriptions-item label="单张限价">
            <!-- <div v-if="record.limitPrice >= 0">【报价】 + {{ record.limitPrice / 100 }}</div>
            <div v-if="record.limitPrice < 0">【报价】 - {{ (0 - record.limitPrice) / 100 }}</div> -->

            <div v-if="record.quotationMode == 1 || record.quotationMode == 3">
              <div v-if="record.limitPrice >= 0">【报价】 + {{ record.limitPrice / 100 }}</div>
              <div v-if="record.limitPrice < 0">【报价】 - {{ (0 - record.limitPrice) / 100 }}</div>
            </div>
            <div v-else>无需设置</div>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-else-if="column.key === 'timePeriod'">
        <a-descriptions bordered size="small" :column="1" :labelStyle="{ width: '120px' }">
          <a-descriptions-item label="生效时间段">
            <div>{{ record.startTime }} - {{ record.endTime }}</div>
          </a-descriptions-item>
        </a-descriptions>
      </template>

      <template v-else-if="column.key === 'action'">
        <a-space>
          <a @click="edit(record)">编辑</a>
          <a-popconfirm title="确定删除？" ok-text="是" cancel-text="否" @confirm="del(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </a-space>
      </template>
    </template>
  </a-table>
  <!-- 推送 -->
  <div style="margin: 5px 0">
    <span>选择推送闲鱼账号：</span>
    <a-select style="width: 150px" placeholder="请选择分组" v-model:value="groupId" @change="selectGroup">
      <a-select-option v-for="(item, index) in groupList" :key="index" :value="item.id">
        {{ item.groupName }}
      </a-select-option>
    </a-select>
    <a-select style="width: 50%; margin-left: 5px" placeholder="请选择" mode="multiple" v-model:value="sendRobat"
      @change="selectSendRobat" allowClear show-search :options="optionList" :filter-option="filterOption">
      <a-select-option v-for="(item, index) in optionList" :key="index" :value="item.value">
        {{ item.label }}
      </a-select-option>
    </a-select>
    <a-button type="primary" style="margin: 0 10px" @click="sendOk">确认推送</a-button>
    <a-button type="primary" @click="SettingTemplate">设置为模板</a-button>
  </div>

  <AddRule ref="addRuleRef" @refresh="getList"></AddRule>

  <Modal :width="800" :height="800" title="请选择勾选单个模板进行保存" ref="AddTemplateRef" @onConfirmAdd="handleConfirm">
    <template #contentValue>
      <addTemplateContent @sendTheID="getTHEID" :screenWidth="screenWidth" :screenHeight="screenHeight" :type="1"
        ref="addTemplateContentRef"></addTemplateContent>
    </template>
  </Modal>
  <!-- 自定义影院设置 -->

  <Modal :width="700" :height="600" title="自定义院线设置" ref="CustomizeRef" @onConfirmAdd="CustomizeRef?.setVisible(false)">
    <template #contentValue>
      <a-button type="primary" @click="CinemasRef.setVisible(true)">添加自定义院线</a-button>
      <div style="height: 10px"></div>

      <a-table style="overflow-y: scroll" :columns="columns1" :data-source="dataSource1" :pagination="pagination1"
        :loading="loading1" @change="changePage1" rowKey="id" :scroll="{ y: 250 }">
        <template #emptyText>
          <a-empty description="暂无数据" />
        </template>

        <!-- <template #headerCell="{ column }"></template> -->

        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'id'">
            {{ record.id }}
          </template>

          <template v-if="column.key == 'lineName'">
            {{ record.lineName }}
          </template>
          <template v-if="column.key == 'cinemaCount'">
            {{ record.cinemaCount }}
          </template>

          <template v-if="column.key == 'action'">
            <!-- <a-button
                type="primary"
                @click="handleEdit(record)"
                class="mr-2"
              >编辑</a-button> -->

            <div style="display: flex">
              <a-popconfirm title="确定要删除吗?" ok-text="确定" cancel-text="取消" @confirm="handleDelete(record)">
                <a-button type="link">删除</a-button>
              </a-popconfirm>

              <div style="width: 10px"></div>
              <a-button type="link" @click="Associated(record)">关联影院</a-button>
            </div>
          </template>
        </template>
      </a-table>
    </template>
  </Modal>
  <!-- 添加院线的弹框 -->
  <Modal title="添加院线" :width="600" :height="600" ref="CinemasRef" @onConfirmAdd="handleConfiormAddCamera">
    <template #contentValue>
      <a-form>
        <a-form-item label="院线名称" name="name">
          <a-input v-model:value="CameraForm.name" placeholder="院线名称"></a-input>
        </a-form-item>
      </a-form>
    </template>
  </Modal>

  <!-- 关联影院的 弹框 -->

  <Modal title="关联影院" :width="1000" :height="600" ref="AssociatedRef" @onConfirmAdd="handleConfiormAssociated">
    <template #contentValue>
      <div class="associated-container">
        <div class="header">
          <a-select v-model:value="cityVal" @change="selectCity" v-if="cityList.length > 0" placeholder="请选择"
            style="width: 200px; text-align: left" show-search :options="cityList" :filter-option="filterOption">
            <a-select-option v-for="(item, index) in cityList" :key="index" :value="item.value">
              {{ item.label }}
            </a-select-option>
          </a-select>

          <a-input-search style="margin-left: 20px" v-model:value="CinemaParams.cinemaName" placeholder="请输入影院名称"
            @search="onSearchCinema" enter-button />
        </div>

        <div class="content-data">
          <div class="left">
            <div class="checkbox-all">
              <a-checkbox v-model:checked="allCheck" @change="handelAllChecked">全选</a-checkbox>
            </div>
            <div class="left-title">查询结果</div>
            <div class="left-box" ref="scrollBox" @scroll="handleScroll">
              <div class="left-item" v-for="(item, index) in CinemaList" :key="item.id" v-if="CinemaList.length > 0">
                <a-checkbox v-model:checked="item.state" @change="selectedGoodsItem(item, index)">
                  <div style="margin-left: 20px; display: flex; align-items: center" :title="item.cinemaName"
                    class="item-text">
                    <div style="max-width: 100px" v-if="!cityVal">({{ item.city }}) -</div>
                    <div class="good-title">
                      {{ item.cinemaName }}
                    </div>
                  </div>
                </a-checkbox>
              </div>

              <a-empty v-else></a-empty>
            </div>
            <div class="pageBox">
              <div>tips:分页获取，向下滑动加载更多</div>
              <div>{{ TemporaryList.length }}/{{ CinemaList.length }}</div>
            </div>
          </div>
          <div class="center" @click="handleClickTemporary">
            <ArrowRightOutlined style="font-size: 18px; color: #1890ff" />
          </div>
          <div class="right">
            <div class="selected-title">已选择的影院</div>
            <div class="right-box">
              <div class="right-item" v-for="(item, index) in selectedCinemaList" :key="item.id"
                :title="item.cinemaName" v-if="selectedCinemaList.length > 0">
                <!-- <img :src="item.image" v-if="item.image" style="width: 30px; height: 30px" alt="" /> -->
                <div class="good-title">({{ item.city }})-{{ item.cinemaName }}</div>
                <div @click="deleteGoodsItem(index, item)">
                  <DeleteOutlined style="font-size: 16px; color: #858a99; cursor: pointer" class="delete-icon" />
                </div>
              </div>
              <a-empty v-else></a-empty>
            </div>
            <div class="pageBox">
              <div></div>
              <div>{{ TemporaryList.length }}/{{ selectedCinemaList.length }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- </div> -->
    </template>
  </Modal>

  <SendTemplate ref="sendTemplateRef"></SendTemplate>
</template>

<style lang="less" scoped>
.hiddenText {
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  line-height: 16px;
}
.associated-container {
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .content-data {
    width: 100%;

    .pageBox {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      margin-top: 10px;
      // margin-left: 10px;
      font-size: 12px;
      color: #1890ff;
    }

    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .left {
      display: flex;
      flex-direction: column;
      // align-items: center;
      position: relative;
      .left-title {
        position: absolute;
        left: 0px;
        top: 20px;
        z-index: 999;
        color: #1890ff;
      }
      .checkbox-all {
        position: absolute;
        left: 12px;
        top: -3px;
        z-index: 999;
      }

      .left-box {
        margin-top: 50px;
        width: 450px;
        height: 360px;
        border: 2px solid #eee;
        border-radius: 5px;
        overflow-y: scroll;
        padding: 10px;

        .left-item {
          display: flex;
          align-items: center;

          .good-title {
            margin-left: 10px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-overflow: ellipsis;
            // width: 300px;

            overflow: hidden;
          }
        }

        .left-item:nth-child(n + 2) {
          margin-top: 4px;
        }

        .left-item:nth-child(2n) {
          background-color: rgba(160, 220, 255, 0.5);
          padding: 5px;
          border-radius: 2px;
        }

        .left-item:nth-child(2n-1) {
          background-color: #fff;
          padding: 5px;
          border-radius: 2px;
        }
      }
    }

    .right {
      position: relative;
      .selected-title {
        position: absolute;
        left: 0;
        top: 20px;
        color: #1890ff;
      }
      .right-box {
        margin-top: 50px;
        width: 400px;
        height: 360px;
        border: 2px solid #eee;
        border-radius: 5px;
        overflow-y: scroll;
        padding: 10px;

        .right-item {
          cursor: pointer;
          display: flex;
          align-items: center;
          justify-content: space-between;

          .good-title {
            margin-left: 10px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-overflow: ellipsis;
            overflow: hidden;
          }
        }

        .right-item:nth-child(n + 2) {
          margin-top: 4px;
        }

        .right-item:nth-child(2n) {
          background-color: rgba(160, 220, 255, 0.5);
          padding: 5px;
          border-radius: 2px;
        }

        .right-item:nth-child(2n-1) {
          background-color: #fff;
          padding: 5px;
          border-radius: 2px;
        }
      }
    }

    .center {
      cursor: pointer;
    }
  }
}
.searchBox {
  margin-bottom: 10px;
  display: flex;

  input {
    width: 200px;
    margin-right: 10px;
  }

  button {
    margin-right: 10px;
  }
}

a:hover {
  color: red;
}
</style>
